package com.platform.common.utils.spring;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Huangkai
 */
@Slf4j
public class RequestHolder {
    public static HttpServletRequest getRequest(){
        /**
         * 获取请求的request
         * */
        log.debug("get Request --- Thread id: {}, Thread name:{}",Thread.currentThread(),Thread.currentThread().getName());
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if(servletRequestAttributes == null){
            return null;
        }
        return servletRequestAttributes.getRequest();
    }
}
